package com.bestcem.xm.txtanls.handler;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import com.alibaba.excel.write.style.AbstractCellStyleStrategy;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

import java.util.List;
import java.util.Map;

/**
 * @author liheng
 * @version v1.0
 * @date 2021/12/14 13:01
 */

public class RecordExcelWriteHandler extends AbstractCellStyleStrategy implements CellWriteHandler {

    /**
     * 表头类型映射
     */
    private Map<String, String> headerTypeMap;

    public void setHeaderTypeMap(Map<String, String> headerTypeMap) {
        this.headerTypeMap = headerTypeMap;
    }
    @Override
    public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Head head, Integer integer, Integer integer1, Boolean aBoolean) {

    }

    @Override
    public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, Head head, Integer integer, Boolean aBoolean) {

    }

    @Override
    public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, WriteCellData<?> cellData, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
//        CellStyle cellStyle = writeSheetHolder.getSheet().getWorkbook().createCellStyle();
//        // 获取表头数据
//        String headerName = head.getHeadNameList().get(0);
//        if (!isHead) {
//            // 数字 日期 类型 居右 其他类型的居左  和 excel的默认保持一致
//            switch (headerTypeMap.getOrDefault(headerName, "string")) {
//                case EXCEL_TYPE_NUMBER:
//                case EXCEL_TYPE_DATE:
//                    cellStyle.setAlignment(HorizontalAlignment.RIGHT);
//                    cell.setCellStyle(cellStyle);
//                    break;
//                default:
//                    cellStyle.setAlignment(HorizontalAlignment.LEFT);
//                    cell.setCellStyle(cellStyle);
//            }
//        }
    }

    @Override
    public void afterCellDispose(WriteSheetHolder writeSheetHolder,
                                 WriteTableHolder writeTableHolder,
                                 List<WriteCellData<?>> list,
                                 Cell cell,
                                 Head head,
                                 Integer relativeRowIndex,
                                 Boolean isHead) {

    }


    @Override
    protected void setHeadCellStyle(Cell cell, Head head, Integer integer) {

    }

    @Override
    protected void setContentCellStyle(Cell cell, Head head, Integer integer) {

    }

}
